//
// Created by lanhu on 2024/8/17.
//

#ifndef LIVER_NCNN_INSTANCE_H
#define LIVER_NCNN_INSTANCE_H

#include <string>
#include <vector>
#include <android/asset_manager_jni.h>
#include <android/asset_manager.h>

#include <opencv2/opencv.hpp>
#include <net.h>

struct Object
{
    cv::Rect rect;
    int label;
    float prob;
};

class NCNNInstance {
public:
    const int DETECT_SUB_SIZE = 640;
    const float PROB_THRESHOLD = 0.5F;
    const float NMS_THRESHOLD = 0.45F;
    const int MAX_STRIDE = 32;
    const int LABEL_NUM = 2;
public:
    NCNNInstance();
    int Init(const char* modelDir);
    int Detect(const cv::Mat& image);
    [[nodiscard]] const std::vector<Object>& objects() const { return m_objects; }
    void Destroy();
    ~NCNNInstance();
private:
    ncnn::Net* m_net;
    std::vector<Object> m_objects;
    std::vector<Object> m_proposals;
    ncnn::UnlockedPoolAllocator m_blob_pool_allocator;
    ncnn::PoolAllocator m_workspace_pool_allocator;
};



#endif //LIVER_NCNN_INSTANCE_H
